import axios from "axios"

// for (let j = 0; j < data.length; j++) {
//   // const x = parseFloat(data[i][0])
//   // const y = parseFloat(data[i][1])
//   // const z = parseFloat(data[i][2])
//   const c = parseFloat(data[j][6])
//   // min_x = min_x > x ? x : min_x
//   // min_y = min_y > y ? y : min_y
//   // min_z = min_z > z ? z : min_z
//   // max_x = max_x < x ? x : max_x
//   // max_y = max_y < y ? y : max_y
//   // max_z = max_z < z ? z : max_z
//   min_c = min_c > c ? c : min_c
//   max_c = max_c < c ? c : max_c
// }


export const parseWell = async () => {
    let wellObjs = []

    const res = await axios.get('/wells_time0.txt')
    let wells = res.data.replace('\\r', '').split('WELL')
    // console.log(wells)

    let wells_count = 0

    for (let well of wells.slice(1, wells.length)) {
      const pros = well.split('\n')

      const wellname = pros[0]

      if (String(wellname).endsWith("SM3/DAY'")) {
        // console.log(wellname, true)
        wells_count++

        const ps = pros
          .slice(1, pros.length)
          .filter((item) => {
            return !(item == '\r' || item == '')
          })
          .map((item) => {
            return item.split(' ').filter((item) => {
              return !(item == '')
            })
          })
        // console.log(ps[9][2], ps[10][2], ps[11][2])

        wellObjs.push({
          // name: wellname.split('')[1],
          name: wellname.split('\'')[1],
          data: ps,
          xcoord: ps[9][2],
          ycoord: ps[10][2],
          depth: ps[11][2],
        })
      }
    }
    console.log(wells_count)
    console.log(wellObjs)
    return wellObjs
  }
